import Mock from 'mockjs'

import qs from 'qs'

Mock.setup({

  // 延时
  timeout: 500 - 1000
})

// mock拦截接口请求

Mock.mock(/\/member\/collect/, 'get', config => {
  // 对查询参数进行处理

  const queryString = config.url.split('?')[1]

  // 将参数转换为obj对象
  const queryObject = qs.parse(queryString)

  const items = []

  // 根据对象中的分页大小回调数据

  for (let i = 0; i < +queryObject.pageSize; i++) {
    items.push(Mock.mock({
      id: '@id',
      name: '@ctitle(10,20)',
      desc: '@ctitle(4,10)',
      price: '@float(100,200,2,2)',
      // http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_7.jpg
      picture: `http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_${Mock.mock('@integer(1,8)')}.jpg`
    }))
  }

  return {
    msg: '获取收藏商品成功',

    result: {
      page: +queryObject.page,
      pageSize: +queryObject.pageSize,
      items,
      count: 35

    }
  }
})
